package com.ctsims.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctsims.common.annotation.Log;
import com.ctsims.common.core.controller.BaseController;
import com.ctsims.common.core.domain.AjaxResult;
import com.ctsims.common.enums.BusinessType;
import com.ctsims.system.domain.CtsScores;
import com.ctsims.system.service.ICtsScoresService;
import com.ctsims.common.utils.poi.ExcelUtil;
import com.ctsims.common.core.page.TableDataInfo;

/**
 * 课程成绩Controller
 *
 * @author hhz
 * @date 2023-04-01
 */
@RestController
@RequestMapping("/system/scores")
public class CtsScoresController extends BaseController
{
    @Autowired
    private ICtsScoresService ctsScoresService;

    /**
     * 查询课程成绩列表
     */
    @PreAuthorize("@ss.hasPermi('system:scores:list')")
    @GetMapping("/list")
    public TableDataInfo list(CtsScores ctsScores)
    {
        startPage();
        List<CtsScores> list = ctsScoresService.selectCtsScoresList(ctsScores);
        return getDataTable(list);
    }

    /**
     * 导出课程成绩列表
     */
    @PreAuthorize("@ss.hasPermi('system:scores:export')")
    @Log(title = "课程成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtsScores ctsScores)
    {
        List<CtsScores> list = ctsScoresService.selectCtsScoresList(ctsScores);
        ExcelUtil<CtsScores> util = new ExcelUtil<CtsScores>(CtsScores.class);
        util.exportExcel(response, list, "课程成绩数据");
    }

    /**
     * 获取课程成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:scores:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ctsScoresService.selectCtsScoresById(id));
    }

    /**
     * 新增课程成绩
     */
    @PreAuthorize("@ss.hasPermi('system:scores:add')")
    @Log(title = "课程成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtsScores ctsScores)
    {
        ctsScores.setCreateBy(getNickname());
        ctsScores.setCreateTime(new Date());
        return toAjax(ctsScoresService.insertCtsScores(ctsScores));
    }

    /**
     * 修改课程成绩
     */
    @PreAuthorize("@ss.hasPermi('system:scores:edit')")
    @Log(title = "课程成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtsScores ctsScores)
    {
        return toAjax(ctsScoresService.updateCtsScores(ctsScores));
    }

    /**
     * 删除课程成绩
     */
    @PreAuthorize("@ss.hasPermi('system:scores:remove')")
    @Log(title = "课程成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ctsScoresService.deleteCtsScoresByIds(ids));
    }
}
